package com.qinghuan.designMode.prePrinciple.segregation;

/**
 * @Auther: qinghuan
 * @Date: 2022/2/16 20:16
 * @Description:接口隔离原则
 *
 */
public class segregation1 {

    public static void main(String[] args) {
        B b = new B();
        b.interface1();

        A a = new A();
        a.depend1(new D());
    }

}

interface Interface1{
    void interface1();
    void interface2();
    void interface3();
    void interface4();
    void interface5();
}

class B implements Interface1 {
    public void interface1() {
        System.out.println("B 实现了 interface1");
    }

    public void interface2() {
        System.out.println("B 实现了 interface2");
    }

    public void interface3() {
        System.out.println("B 实现了 interface3");
    }

    public void interface4() {
        System.out.println("B 实现了 interface4");
    }

    public void interface5() {
        System.out.println("B 实现了 interface5");
    }
}

class D implements Interface1{
    public void interface1() {
        System.out.println("D 实现了 interface1");
    }

    public void interface2() {
        System.out.println("D 实现了 interface2");
    }

    public void interface3() {
        System.out.println("D 实现了 interface3");
    }

    public void interface4() {
        System.out.println("D 实现了 interface4");
    }

    public void interface5() {
        System.out.println("D 实现了 interface5");
    }
}

class A{//A类通过接口B实现了接口1，2，3
    public void depend1(Interface1 interface1) {
        interface1.interface1();
    }
    public void depend2(Interface1 interface1) {
        interface1.interface2();
    }
    public void depend3(Interface1 interface1) {
        interface1.interface3();
    }
}

class C{//C类通过接口D实现1，3，5
    public void depend1(Interface1 interface1) {
        interface1.interface1();
    }
    public void depend2(Interface1 interface1) {
        interface1.interface3();
    }
    public void depend3(Interface1 interface1) {
        interface1.interface5();
    }
}